<!--混凝土拌和站---动态监控--实时监控-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-02 13:13:25
 * @LastEditors: 卡卡 1071780426@qq.com
 * @LastEditTime: 2023-09-14 13:46:48
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        name="pitchManage_treeCheck"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left left_select" style="width: 100%">
          <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker>
        </div>
        <!-- 顶部按钮 -->
        <div class="print" style="display: flex; justify-content: flex-end">
          <el-button
            type="primary"
            icon="el-icon-refresh"
            size="small"
            @click="yj_searchForm(getList)"
          >
          </el-button>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="small"
            @click="yj_editForm(2)"
            >查看
          </el-button>
          <el-button
            type="primary"
            icon="el-icon-circle-plus-outline"
            size="small"
            @click="yj_editForm(0)"
          >
            新增</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-edit"
            size="small"
            @click="yj_editForm(1)"
          >
            编辑</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-delete"
            size="small"
            @click="rowDelete()"
            >删除
          </el-button>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @openDialog="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          :info="queryCriteriaData"
          v-if="navigatepageNums > 1"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>
      <!--弹框 查看 -->
      <div class="Control-1 mechanism_dialogS mixProportion">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div class="jpbox"></div>
          <div
            class="dialogBody common"
            :style="{ height: '730px' }"
            style="overflow: hidden"
          >
            <div class="baseTitle">基本信息</div>
            <div style="height: 140px">
              <publicForm
                ref="publicForm"
                lableWidth="155px"
                :formObj="formObj"
                :formData="formData"
              >
              </publicForm>
            </div>
            <div class="baseTitle">筛分实验数据</div>
            <div
              v-if="formData.sieveList.length != 0"
              style="height: 480px"
              class="fillableBox"
            >
              <tableData
                :config="table_sieve"
                :currentRow="false"
                :dataList="formData.sieveList"
                :loading="listsieveLoading"
                placeholderText=""
                @inputValue="inputValue"
                statusType="1"
              />
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="yj_saveForm('publicForm')"
              >保存</el-button
            >
            <!-- <el-button type="warning" @click="close">关闭</el-button> -->
            <el-button type="warning" @click="dialogEditVisible = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>
<script>
import vDatePicker from "@/components/public/v-DatePicker";
import tree from "@/components/public/pitchManage_tree"; //左侧机构树
import TableData from "@/components/public/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项
// import commonPage from '@/components/pitchManage/dyMonitorManage/real_timeDataPage';//主页面列表

import {
  getUserCompanyTreeList, //左侧机构树接口
  getAsphaltRecipeLists, //沥青拌合站 基础设置 查询-配方管理列表页
  saveAsphaltRecipe, //沥青拌合站 基础设置 配方管理-配方保存接口
  delAsphaltRecipe, // 沥青拌合站 基础设置  删除-配方管理
  getAsphaltRecipeDetail, // 沥青拌合站 基础设置  查询-配方管理详情页
} from "@/api/request.js";

export default {
  name: "mixProportion",
  data() {
    return {
      name: "mixProportion", //按钮配置页面代号
      table_config: formJs.table_config, // 列表配置项
      table_sieve: formJs.sieveAperture, //级配设置
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {}, //分页
      value2: "", //主页面日期筛选绑定值
      tableData: [], //表格列表数据列表
      // sieveApertureData: formJs.sieveApertureData,//级配设置
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      showName: "未选择公司",
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      listsieveLoading: false, //级配设置
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formData: {
        fId: "", // 配方fid
        fStandard: "", // 执行标准
        fRecipenumber: "", // 配合比编号
        fAsphaltaggregateratiogoalvalue: "", // 油石比（必填）
        fPitchnum: "", // 沥青标号/改性沥青品种
        fJptype: "", // 级配类型
        fMixturetype: "", // 混合料类型
        fStartdates: "", // 启用时间
        fCompanyid: "",
        sieveList: [],
      },
      formObj: formJs.formObj,
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", //拌合站
        machineId: "", //拌合机
        fConstructionhorizon: "", // 施工层位
        fMixturetype: "", //  沥青混合料类型
        warningLevel: "", // 预警等级
        fCloseoperation: "", //闭合状态
        page: 1, // 当前页码
        pageSize: 20, // 每页显示条数
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [], //树状图默认选中id
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      dialogTitle: "查看",
      commonData: {},
      btnShow: true, //保存按钮是否显示
      publicTable: true, //新增配方表
      rowInfo: null,
    };
  },
  components: {
    vDatePicker, //时间选择器
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    Pagination, //分页
    publicForm,
    // commonPage
  },
  mounted() {
    // this.table_config.operation.cols = [
    //     {
    //         label: "查看",
    //         prop: 'F_CloseOperations',
    //         type: 'primary',
    //         handleRow: this.handleRow
    //     }

    // ]
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
      this.getList = JSON.parse(sessionStorage.getItem("pitchManage_getLists"));
    }
    if (JSON.parse(sessionStorage.getItem("pitchManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("pitchManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 点击当前行
    rowChange(val) {
      // console.log(val);
      this.rowInfo = val;
      // this.yj_viewForm(val)
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "3", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("pitchManage_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.yj_searchForm(this.getList); // 调用主页面列表接口
          } else {
            this.$message.error("获取组织机构失败", res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.rowInfo = null;

      if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("pitchManage_getLists")
        );
        this.getList.fCompanyid = data.fCompanyid;
        this.value2 = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.fCompanyid = data.fCompanyid;
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.fConstructionhorizon = ""; // 施工层位
        this.getList.fMixturetype = ""; //  沥青混合料类型
        this.getList.warningLevel = ""; // 预警等级
        this.getList.fCloseoperation = ""; // 闭合状态
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
      this.getList.stationId = "";
      this.getList.machineId = "";
      this.getList.page = 1;

      this.yj_searchForm(this.getList);
    },
    // 新增编辑查看弹框
    yj_editForm(status) {
      if (status == 0) {
        //新增
        this.dialogTitle = "新增";
        this.formData = {
          //新增
          fId: "", // 配方fid
          fStandard: "", // 执行标准
          fRecipenumber: "", // 配合比编号
          fAsphaltaggregateratiogoalvalue: "", // 油石比（必填）
          fPitchnum: "", // 沥青标号/改性沥青品种
          fJptype: "", // 级配类型
          fMixturetype: "", // 混合料类型
          fCompanyid: this.getList.fCompanyid,
          fStartdates: this.common.getDay(0) + " " + "23:59:59", // 启用时间
          sieveList: [],
        };
        getAsphaltRecipeDetail({ fId: "" }).then((res) => {
          if (res.errcode == 0) {
            this.formData.sieveList = res.data.asphaltRecipe.sieveList;

            console.log(this.formData.sieveList);
          } else {
            this.$message.error("获取详情接口报错", res.msg);
          }
        });

        // this.sieveApertureData = formJs.sieveApertureData
        this.formObj.map((item) => {
          item.disabled = false;
          item.rules[0].required = true;
        });
        this.dialogEditVisible = true;
        this.btnShow = true; //新增时按钮显示
        // this.loadingEditDialog = true
      } else if (status == 1) {
        //编辑
        this.dialogTitle = "编辑";

        this.btnShow = true; //编辑时按钮显示
        this.formObj.map((item) => {
          item.disabled = false;
          item.rules[0].required = true;
        });
        this.yj_viewForm();
      } else if (status == 2) {
        //

        this.dialogTitle = "查看";
        this.btnShow = false; //编辑时按钮显示
        this.formObj.map((item) => {
          item.disabled = true;
          item.rules[0].required = false;
        });
        this.yj_viewForm();
      }
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      window.sessionStorage.setItem(
        "pitchManage_getLists",
        JSON.stringify(data)
      );
      getAsphaltRecipeLists(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            this.queryCriteriaData = res.data.pageInfo; //分页信息
            this.navigatepageNums =
              this.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    yj_viewForm() {
      var row = this.rowInfo;
      if (row != null) {
        var id = row.fId;
        this.fId = row.fId;
        this.dialogEditVisible = true;
        this.loadingEditDialog = true;
        // this.commonData = {
        //     fId: id,
        //     companyId: this.getList.fCompanyid,
        //     machineId: row.fMachineid
        // }

        getAsphaltRecipeDetail({ fId: id }).then((res) => {
          if (res.errcode == 0) {
            this.loadingEditDialog = false;
            this.formData = res.data.asphaltRecipe;

            console.log(res.data);
          } else {
            this.$message.error("获取详情接口报错", res.msg);
          }
        });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },
    yj_saveForm() {
      if (this.publicTable == true) {
        if (this.$refs.publicForm.submitForm()) {
          saveAsphaltRecipe(this.formData).then((res) => {
            if (res.errcode == 0) {
              this.yj_searchForm(this.getList);
              this.dialogEditVisible = false;
              this.$refs["publicForm"].resetFields();
              // this.$emit('searchForm')
              // this.$emit('dialogShow', false)
              this.$message.success("新增成功");
            } else {
              this.$message.error("新增失败", res.msg);
              console.log("接口报错");
            }
          });
          console.log("闭合申请单", this.formData);
        } else {
          console.log("error");
        }
      } else {
        console.log(123);
      }

      // this.handleData.fCompanyid = this.allData.companyId// 施工标段id
      // if (this.checkStatus == 0) {//闭合申请单
      //     if (this.$refs.publicForm0.submitForm()) {
      //         this.saveForm(this.handleData)
      //         console.log('闭合申请单', this.handleData);
      //     } else {
      //         console.log("error")
      //     }
      // } else if (this.checkStatus == 1) {
      //     if (this.$refs.publicForm1.submitForm()) {
      //         console.log('一级审核', this.handleData);
      //         this.saveForm(this.handleData)

      //     } else {
      //         console.log("error")
      //     }
      // } else if (this.checkStatus == 2) {
      //     if (this.$refs.publicForm2.submitForm()) {
      //         console.log('二级审核', this.handleData);
      //         this.saveForm(this.handleData)

      //     } else {
      //         console.log("error")
      //     }
      // }
    },
    inputValue(val, table) {
      this.formData.sieveList = table;
      console.log(val);
    },
    rowDelete() {
      if (this.rowInfo != null) {
        this.listLoading = true;
        this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            delAsphaltRecipe({ fId: this.rowInfo.fId }).then((res) => {
              if (res.errcode == 0) {
                this.listLoading = false;
                this.yj_searchForm(this.getList);
                this.$message.success("删除成功");
              } else {
                this.$message.error("删除失败", res.msg);

                return false;
              }
            });
          })
          .catch(() => {
            this.listLoading = false;
            this.$message("取消删除");
          });
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },
    // 公共弹框是否显示
    loadingShow(e) {
      this.loadingEditDialog = e;
    },
    // 时间间隔
    // selectTime(e) {
    //     this.getList.startDates = e[0] + " " + "00:00:00"// 开始时间
    //     this.getList.endDates = e[1] + " " + "23:59:59"// 截至时间
    //     this.yj_searchForm(this.getList);
    // },
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.yj_searchForm(this.getList);
    },
    getDate() {
      if (JSON.parse(sessionStorage.getItem("pitchManage_getLists"))) {
        this.getList = JSON.parse(
          sessionStorage.getItem("pitchManage_getLists")
        );
        this.getList.page = 1;
        this.value2 = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
    },
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.jpbox {
  height: 100%;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  // overflow-y: auto;
  // display: flex;
  // flex-direction: column;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.mixProportion /deep/ .el-form-item__content {
  margin-left: 180px !important;
}

.fillableBox /deep/ .el-table .cell {
  padding: 0 !important;
}

.fillableBox /deep/ .el-input__inner {
  border: none;
  height: 31px !important;
  padding: 0 !important;
  text-align: center;
}
</style>